//
//  MainTabBar.swift
//  Weibo
//
//  Created by mac on 16/1/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusBtn)
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var plusBtn: UIButton = UIButton(backImageName: "tabbar_compose_button", btnImageName: "tabbar_compose_icon_add")
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        var index: Int = 0
        let w: Int = Int(self.bounds.width * 0.2)
        let h: Int = Int(self.bounds.height)
        
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        for subview in subviews {
            
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
                subview.frame = CGRectOffset(rect, CGFloat(w * index), 0)
                
                index += (index == 1 ? 2 : 1)
            }
        }
        
        plusBtn.frame = CGRectOffset(rect, CGFloat(w * 2), 0)
//        print(plusBtn)
    }

}
